package b3.util
{
	import b3.net.*;
	
	import flash.display.Sprite;
	import flash.filters.*;
	import flash.text.*;
	
	public class BFont
	{
		static public const fontName:String = "微软雅黑";
		static public const brightFilter:Array =
				[1,0,0,0,15,
			     0,1,0,0,15,
			     0,0,1,0,15,
			     0,0,0,1,0 ];
		static public const darkFilter:Array =
				[1,0,0,0,-50,
			     0,1,0,0,-50,
			     0,0,1,0,-50,
			     0,0,0,1,0 ];
		static public const normalFilter:Array =
				[1,0,0,0,0,
			     0,1,0,0,0,
			     0,0,1,0,0,
			     0,0,0,1,0 ];
		static public const blackWhiteFilter:Array = [0.3086, 0.6094, 0.0820, 0, 0,
		 											  0.3086, 0.6094, 0.0820, 0, 0,
												      0.3086, 0.6094, 0.0820, 0, 0,
												      0,      0,      0,      1, 0];
		static public const redFilter:Array = [1,0,0,0,100,
								    		   0,1,0,0,0,
										       0,0,1,0,0,
										       0,0,0,1,0 ];
		static public const yellowFilter:Array = [1,0,0,0,100,
								    		   0,1,0,0,100,
										       0,0,1,0,0,
										       0,0,0,1,0 ];
		static public const greenFilter:Array = [1,0,0,0,0,
								    		     0,2,0,0,100,
										         0,0,1,0,0,
										         0,0,0,1,0 ];
		static public const blueFilter:Array = [1,0,0,0,0,
								    		     0,1,0,0,0,
										         0,0,2,0,100,
										         0,0,0,1,0 ];
		static public var stageWidth:int = 760;
		static public var stageHeight:int = 600;
		static public const userNameColor:int = 0x0000FF;
		static public const animalNameColor:int = 0xFF0000;
		static public const roundRecColor:int = 0x60442B;

		public function BFont()
		{
		}
		
		//色相偏移    
		public static function createHueFilter(n:Number):Array
		{
			const p1:Number = Math.cos(n * Math.PI / 180);
			const p2:Number = Math.sin(n * Math.PI / 180);
			const p4:Number = 0.213;
			const p5:Number = 0.715;
			const p6:Number = 0.072;
			return [p4 + p1 * (1 - p4) + p2 * (0 - p4), p5 + p1 * (0 - p5) + p2 * (0 - p5), p6 + p1 * (0 - p6) + p2 * (1 - p6), 0, 0,
			p4 + p1 * (0 - p4) + p2 * 0.143, p5 + p1 * (1 - p5) + p2 * 0.14, p6 + p1 * (0 - p6) + p2 * -0.283, 0, 0,
			p4 + p1 * (0 - p4) + p2 * (0 - (1 - p4)), p5 + p1 * (0 - p5) + p2 * p5, p6 + p1 * (1 - p6) + p2 * p6, 0, 0, 0, 0, 0, 1, 0];
		}
		
		//将数字格式化为逗号分隔
		public static function formatNumWithComa(num:int):String
		{
			var res:String = "";
			while (num > 999)
			{
				var thousand:int = num % 1000; 
				res = "," + (thousand < 10 ? "0" : "") + (thousand < 100 ? "0" : "") + thousand + res;
				num /= 1000;
			}
			res = num + res;
			return res;
		}
		
		//格式化排名
		public static function formatRank(ranking:int, FontClass:Class):Sprite
		{
			var container:Sprite = new Sprite();
			if (ranking == 1)
			{
				//st
				font = new FontClass();
				digit = font.getChildAt(14) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				font = new FontClass();
				digit = font.getChildAt(13) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				//数字
				var font:Sprite = new FontClass();
				var digit:Sprite = font.getChildAt(12) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
			}
			else if (ranking == 2)
			{
				//nd
				font = new FontClass();
				digit = font.getChildAt(17) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				font = new FontClass();
				digit = font.getChildAt(16) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				//数字
				font = new FontClass();
				digit = font.getChildAt(15) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
			} 
			else if (ranking == 3)
			{
				//rd
				font = new FontClass();
				digit = font.getChildAt(20) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				font = new FontClass();
				digit = font.getChildAt(19) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				//数字
				font = new FontClass();
				digit = font.getChildAt(18) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
			}
			if (ranking > 3)
			{
				//th
				font = new FontClass();
				digit = font.getChildAt(11) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				font = new FontClass();
				digit = font.getChildAt(10) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				//数字
				var count:int = 0;
				while (ranking > 0 || count == 0)
				{
					font = new FontClass();
					digit = font.getChildAt(ranking % 10) as Sprite;
					digit.x = -container.width - digit.width;
					container.addChild(digit);
					ranking /= 10;
					count++;
				}
			}
			var res:Sprite = new Sprite();
			container.x = container.width;
			res.addChild(container);
			return res;
		}
		
		//格式化数字
		public static function formatNum(num:int, FontClass:Class):Sprite
		{
			var container:Sprite = new Sprite();
			var count:int = 0;
			while (num > 0 || count == 0)
			{
				var font:Sprite = new FontClass();
				var digit:Sprite = font.getChildAt(num % 10) as Sprite;
				digit.x = -container.width - digit.width;
				container.addChild(digit);
				num /= 10;
				count++;
			}
			var res:Sprite = new Sprite();
			container.x = container.width;
			res.addChild(container);
			return res;
		}
		
		//规范显示时间: xx小时xx分xx秒
		public static function formatTime(seconds:int):String
		{
        	var hours:int = seconds / 3600;
        	var minutes:int = seconds / 60 % 60;
        	var seconds:int = seconds % 60;
        	var timeStr:String;
        	if (seconds < 10)
        		timeStr = "0" + seconds + "秒";
        	else
        		timeStr = seconds + "秒";
        	if (minutes > 0)
        	{
        		if (minutes < 10)
        			timeStr = "0" + minutes + "分" + timeStr;
        		else
        			timeStr = minutes + "分" + timeStr; 
        	}
        	if (hours > 0)
        	{
        		timeStr = hours + "小时" + timeStr;
        	}
        	return timeStr;
		}
		
	}
}